package com.leetcode.Offer;

public class JZ55_3 {
    public boolean isBalanced(TreeNode root) {
        if (root == null) {
            return true;
        }
        return Math.abs(dept(root.left) - dept(root.right)) <= 1 && isBalanced(root.left) && isBalanced(root.right);
    }

    public int dept(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(dept(root.left), dept(root.right)) + 1;
    }

}
